package C_Paper;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class C100_22 {
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        int n = scanner.nextInt();
//        int t = scanner.nextInt();
//        int[][] sv = new int[n][2];
//        for (int i = 0; i < n; i++) {
//            sv[i][0] = scanner.nextInt();
//            sv[i][1] = scanner.nextInt();
//        }
//        LocalDateTime parse = LocalDateTime.parse("", DateTimeFormatter.ofPattern(""));
//        System.out.println(jf(t, sv));
//    }
//    public static int jf(int t,int[][] sv){
//        Arrays.sort(sv, Comparator.comparing(a -> a[0]));
//        System.out.println(Arrays.deepToString(sv));
//        int i = 1;
//        int f = 0;
//        int jf = 0;
//        do{
//            int x = 0;
//            for (; f < sv.length; f++) {
//                if (i > sv[f][0]) break;
//                if (sv[f][1] > x) x = sv[f][1];
//            }
//            jf += x;
//            i++;
//        }while (f < sv.length);
//        return jf;
//    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt(); // 任务数量
        int T = scanner.nextInt(); // 可用于处理任务的时间

        Task[] tasks = new Task[N];
        for (int i = 0; i < N; i++) {
            int sla = scanner.nextInt();
            int score = scanner.nextInt();
            tasks[i] = new Task(sla, score);
        }
        scanner.close();

        // 动态规划数组，dp[i][j]表示处理前i个任务，用j时间最多可以获得的积分
        int[][] dp = new int[N + 1][T + 1];
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= T; j++) {
                if (tasks[i - 1].sla > j) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1] + tasks[i - 1].score);
                }
            }
        }

        System.out.println("可获得的最多积分：" + dp[N][T]);
    }
}

class Task {
    int sla;
    int score;

    public Task(int sla, int score) {
        this.sla = sla;
        this.score = score;
    }
}
